import vue from '@vitejs/plugin-vue';
import eslint from 'vite-plugin-eslint';
import { viteMockServe } from 'vite-plugin-mock';
import { UserConfigExport, ConfigEnv, loadEnv } from 'vite';
import Components from 'unplugin-vue-components/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
// https://vitejs.dev/config/
export default ({ mode, command }: ConfigEnv): UserConfigExport => {
  // According to the project configuration. Can be configured in the .env file
  const env = loadEnv(mode, process.cwd());
  return {
    plugins: [
      vue(),
      eslint(),
      viteMockServe({
        mockPath: 'mock',
        localEnabled: false,
        prodEnabled: command !== 'serve' && env.VITE_PRODMOCK === 'true',
        injectCode: `
          import { setupProdMockServer } from './mock/mockProdServer';
          setupProdMockServer();
        `,
      }),
      Components({
        resolvers: [NaiveUiResolver()],
      }),
    ],
  };
};
